using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

namespace net.notdot.Attercop {
    [Serializable()]
    public class IncomingFileMessage : Message, TcpMessage {
        public readonly string Path = "";
        public readonly long Offset;

        static IncomingFileMessage() { ClientInstance.AddMessageHandler<IncomingFileMessage>(); }

        public IncomingFileMessage(MessageAddressing addressing, string path, long offset)
            : base(addressing) {
            this.Path = path;
            this.Offset = offset;
        }

        public IncomingFileMessage(MessageAddressing addressing, string path)
            : this(addressing, path, 0) {
        }

        protected IncomingFileMessage(MessageReader reader)
            : base(reader)
        {
            reader.BeginRegion();
            reader.ReadByte();  //Version
            this.Path = reader.ReadString();
            this.Offset = reader.ReadInt64();
            reader.EndRegion();
        }

        public override void Serialize(MessageWriter writer)
        {
            base.Serialize(writer);

            writer.BeginRegion();
            writer.Write((byte)0);  //Version
            writer.Write(this.Path);
            writer.Write(this.Offset);
            writer.EndRegion();
        }
    }
}
